package com.undergroundbiology.undergroundbiology;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class News extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gallery);


        final WebView webview = (WebView)findViewById(R.id.webView);
        webview.getSettings().setJavaScriptEnabled(true);
        WebSettings webSettings = webview.getSettings();
        webview.getSettings().setBuiltInZoomControls(true);
        webview.getSettings().setAppCacheEnabled(true);
        webview.getSettings().setSaveFormData(true);
        webview.getSettings().setAllowFileAccess(true);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayUseLogoEnabled(true);
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                webview.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('fa-bars')[0].style.display='none'; " +
                        "})()");
                webview.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('fa')[0].style.display='none'; " +
                        "})()");
                webview.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('sidebar-toggle')[0].style.display='none'; " +
                        "})()");
                webview.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('site-branding')[0].style.display='none'; " +
                        "})()");
            }
        });

        webview.loadUrl("http://www.TrinovaLabs.com/?page_id=178");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.menu_news, menu);
        return true;
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        WebView myWebView = (WebView) findViewById(R.id.webView);
        myWebView.setWebViewClient(new WebViewClient());


        if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
            myWebView.goBack();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

}
